Determining Which Interface an Object Supports

The QueryInterface method lets an application query an object to determine which interfaces it supports. The sample application sets the ppv pointer to the current interface.

STDMETHODIMP CAVIFileCF::QueryInterface(

    const IID FAR& iid,

    void FAR* FAR* ppv)

    if (iid == IID_IUnknown)

        *ppv = this;                     // set the interface pointer

                                         // to this instance

    else if (iid == IID_IClassFactory)

        *ppv = this;                     // second chance to set the

                                         // interface pointer to this

                                         // instance

    else

        return ResultFromScode(E_NOINTERFACE);

    AddRef();  //Increment the reference count

    return NULL;

}